package com.library.control.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.library.model.dto.user.UserDTO;
import com.library.model.service.UserService;

public class UserDetailController extends AbstractFormController{

	private UserService userservice;
	
	public void setUserservice(UserService userservice) {
		this.userservice = userservice;
	}
	
	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
		ModelAndView mav=new ModelAndView();
		userservice.updateUser((UserDTO)arg2);
		mav.setViewName("userupdateok");
		return mav;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		ModelAndView mav=new ModelAndView();
		String id=request.getParameter("member_id");
		UserDTO dto=userservice.getUser(id);
		mav.addObject("userdetail",dto);
		mav.setViewName("userdetail");
		return mav;
	}

}
